﻿using System.Threading.Tasks;
using Abp.Authorization;
using Abp.Runtime.Session;
using ABCNet.Configuration.Dto;

namespace ABCNet.Configuration
{
    //[AbpAuthorize]
    public class ConfigurationAppService : ABCNetAppServiceBase, IConfigurationAppService
    {
        public async Task ChangeUiTheme(ChangeUiThemeInput input)
        {
            await SettingManager.ChangeSettingForUserAsync(AbpSession.ToUserIdentifier(), AppSettingNames.UiTheme, input.Theme);
        }


        public async Task SaveSysConfig(SysConfigDto input)
        {
            await SettingManager.ChangeSettingForTenantAsync(1, AppSettingNames.SystemClosed, input.SystemClosed ? "1" : "0");
            await SettingManager.ChangeSettingForTenantAsync(1, AppSettingNames.DisableAreaCode, input.DisableAreaCode);
        }

        public async Task<SysConfigDto> GetSysConfig()
        {
            SysConfigDto dto = new SysConfigDto();
            dto.DisableAreaCode = await SettingManager.GetSettingValueForTenantAsync(AppSettingNames.DisableAreaCode, 1);
            var c = await SettingManager.GetSettingValueForTenantAsync(AppSettingNames.SystemClosed, 1);
            dto.SystemClosed = c == "1" || c.ToUpper() == "TURE";
            return dto;
        }

    }
}
